package com.obrempon.credit.market.ui.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.obrempon.credit.market.R
import com.obrempon.credit.market.common.CommonDialog
import com.obrempon.credit.market.databinding.ObremponAuthStepWalletAccountBindOtherDialogBinding
import com.obrempon.credit.market.event.ObremponEventPointType
import com.obrempon.credit.market.utils.ObremponImageUtil
import org.json.JSONObject

/**
 * ObremponCredit
 * @Author wwdeng
 * @CreateTime: 2024/11/21 13:45
 * @Annotation：绑卡换卡dialog
 */
class ObremponWalletAccountBindOtherDialog: CommonDialog {
    private lateinit var binding: ObremponAuthStepWalletAccountBindOtherDialogBinding
    private var mCallback: IDialogCallback? = null
    //事件备注
    private var eventRemark = ""

    constructor(context: Context) : super(context) {}
    constructor(context: Context, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context, remark: String,callback: IDialogCallback?) : super(context) {
        mCallback = callback
        eventRemark = remark
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun takeObremponRootView(): View {
        binding = ObremponAuthStepWalletAccountBindOtherDialogBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initObremponView() {

    }

    override fun initObremponListener() {
        setOnClickListener(binding.buttonWalletOtherCancel)
        setOnClickListener(binding.buttonWalletOtherConfirm) //两个按钮 又侧按钮
        setOnClickListener(binding.imageWalletAccountBindOtherClose)//关闭
    }

    override fun takeObremponData() {
    }

    override fun onObremponViewClick(v: View?) {
        dismiss()
        when(v!!.id){
            R.id.buttonWalletOtherCancel -> {
                addEventPointRequestAction(ObremponEventPointType.CLICK.OBREMPON_CLICK_USER_ACCOUNT_BIND_OTHER_CANCEL,eventRemark)
            }
            R.id.buttonWalletOtherConfirm -> {
                addEventPointRequestAction(ObremponEventPointType.CLICK.OBREMPON_CLICK_USER_ACCOUNT_BIND_OTHER_CONFIRM,eventRemark)
            }
        }
        if(mCallback != null){
            mCallback!!.onClick(v)
        }
    }

    /**
     * 设置账户信息
     */
    fun showObremponWalletAccountInfo(info: JSONObject){
        binding.walletIndex.text = String.format(context.getString(R.string.obrempon_auth_step_wallet_account_index),1)
        ObremponImageUtil.instance.loadImageUrl(context,binding.walletTypeLogo,info.optString("logo"), R.mipmap.obrempon_holder)
        binding.walletTypeTitle.text = info.optString("desc")
        binding.walletAccountMobile.text = info.optString("walletMobile")
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }

    override fun onStart() {
        super.onStart()
        addEventPointRequestAction(ObremponEventPointType.DIALOG.OBREMPON_DIALOG_USER_ACCOUNT_BIND_OTHER_TIPS_SHOW,eventRemark)
    }

    override fun dismiss() {
        super.dismiss()
        addEventPointRequestAction(ObremponEventPointType.DIALOG.OBREMPON_DIALOG_USER_ACCOUNT_BIND_OTHER_TIPS_DISMISS,eventRemark)
    }
}